package com.wwwarehouse.contract.order_information;


import android.os.Bundle;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.fastjson.JSON;
import com.wwwarehouse.common.fragment.CommonBasePagerFragment;
import com.wwwarehouse.common.tools.ToastUtils;
import com.wwwarehouse.contract.bean.ProductDetailsBean;
import com.wwwarehouse.contract.core.ContractConstant;

import java.util.HashMap;
import java.util.Map;

/**
 * Creator by zhenwang.xiang on 2017/11/2 16:17
 * Description: 我买到的商品明细Viewpager
 */
@Route(path = ContractConstant.PATH_BUYGOODDETAILVIEWPAGERFRAGMENT)
public class BuyGoodDetailViewPagerFragment extends CommonBasePagerFragment {
    private String contractUkid;

    @Override
    public void requestDatas() {
        super.requestDatas();

        if (getArguments()!=null){
            contractUkid=getArguments().getString("contractUkid");
        }

        //网络请求
        requestHttp();

    }

    @Override
    public void setTitle() {
        super.setTitle();
        if (peekFragment() instanceof BuyGoodDetailViewPagerFragment) {
            mActivity.setTitle("商品明细");
        }
    }

    private void requestHttp() {
        Map<String, Object> map = new HashMap<>();
        map.put("contractUkid", contractUkid);
        map.put("page", 1);
        map.put("size", "7");
        loadData(ContractConstant.GET_ITEMDETAILS, map, 0);
    }


    @Override
    public void onRefreshListener() {
        requestHttp();
    }

    @Override
    public void onDownPull() {
    }

    @Override
    public void onLoadSuccess(String data, int what) {
        if (0 == what) {
            ProductDetailsBean bean = JSON.parseObject(data, ProductDetailsBean.class);
            if (null != bean) {
                Bundle bundle = new Bundle();
                bundle.putString("contractUkid", contractUkid);
                try {
                    setData(bean.getTotal(), 7, "com.wwwarehouse.contract.order_information.BuyGoodDetailFragment", bundle, bean.getList());
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
    }

    @Override
    public void onLoadError(String errorInfo) {
        ToastUtils.showToast(errorInfo);
    }
}
